import { customRef } from "vue";

export default function (initValue: any, delay: number) {
  let msg = customRef((track, trigger) => {
    return {
      // when read, call get
      get() {
        track();
        return initValue;
      },
      // when update, call set
      set(value) {
        clearTimeout(delay);
        delay = setTimeout(() => {
          initValue = value;
          trigger();
        }, 1000);
      },
    };
  });
  return {msg}
}
